//3.

const fp = require("lodash/fp");
const { Maybe, Container } = require("./support");

let maybe = Maybe.of([5, 6, 1]);

let xs = Container.of(["do", "ray", "me", "fa", "so", "la", "ti", "do"]);

let safeProp = fp.curry(function(x, o) {
  return Maybe.of(o[x]);
});

let user = { id: 2, name: "Albert" };



//1.实现一个ex1函数使用fp.add和fp.map 创建一个可以让值增加的函数
let ex1 = () => {
  return number => maybe.map(fp.map(fp.add(number)));
};
let result = ex1();
console.log(result(10)._value);




//2.实现一个ex2 能够使用fp.first 获取列表的第一个元素
let ex2 = () => {
  return value => value.map(fp.first);
};
let ex2Result = ex2();
console.log(ex2Result(xs)._value);




//3.实现一个ex3 能够使用safeProp和fp.first找到user名字的首字母

let ex3 = () => {
  let info = fp.flowRight(value => fp.first(value._value), safeProp("name"));
  // console.log(info(user));
  return info;
};
let ex3Result = ex3();
console.log(ex3Result(user));





//4.重写ex4
let ex4 = n => {
  return Maybe.of(n).map(parseInt);
};

let ex4Result = ex4("123abc");
console.log(ex4Result._value);
